package com.wei.czz.framework.rabbitMQ.listener;

import com.wei.czz.common.enums.rabbitMQ.MqEnum;
import com.wei.czz.common.po.game.GameUserPo;
import com.wei.czz.framework.game.service.GamePrizeService;
import com.wei.czz.framework.game.service.GameUserService;
import lombok.AllArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

/**
 * Created by IntelliJ IDEA.
 *
 * @author wei
 * date: 2023-03-23 17:33:13
 * className: GameQueueListener 游戏相关消息队列监听类
 * version: 1.0
 * description:
 */
@Component
@AllArgsConstructor
public class GameQueueListener {

    private static final Logger log = LoggerFactory.getLogger(GameQueueListener.class);

    private final GamePrizeService gamePrizeService;

    private final GameUserService gameUserService;

    /**
     * 扣减游戏奖品剩余数量消息监听方法
     * @param prizeId 奖品主键
     */
    @RabbitListener(queues = {MqEnum.Queue.GAME_PRIZE})
    public void gamePrizeMessage(Long prizeId) {
        log.info("开始异步扣减游戏奖品剩余数量业务。prizeId={}", prizeId);

        gamePrizeService.addUseNum(prizeId);

        log.info("异步扣减游戏奖品剩余数量业务结束");
    }

    /**
     * 扣减游戏用户剩余游戏次数消息监听方法
     * @param gameUserPo 游戏用户对象
     */
    @RabbitListener(queues = {MqEnum.Queue.GAME_USER})
    public void gameUserMessage(GameUserPo gameUserPo) {
        log.info("开始异步扣减游戏用户剩余游戏次数业务。gameUserPo={}", gameUserPo);

        gameUserService.addUseNum(gameUserPo);

        log.info("异步扣减游戏用户剩余游戏次数业务结束");
    }

}
